package com.mtx.util;

import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;


public class MapperUtils {
    private static final MapperFacade mapperFacade;
    private static final MapperFactory mapperFactory;

    static {
        mapperFactory = new DefaultMapperFactory.Builder().build();
        mapperFacade = mapperFactory.getMapperFacade();
    }

    /**
     * 将对象sourceObject的值拷贝到对象targetObject中
     */
    public static void copyObject(Object sourceObject, Object targetObject) {
        mapperFacade.map(sourceObject, targetObject);
    }

    public static Object copyObject(Object sourceObject, Class targetObject) {
        return mapperFacade.map(sourceObject, targetObject);
    }

   //  可以封装更多的常用方法
 
    /**
     * 提供getMapperFactory方便调用其他方法
     */
    public static MapperFactory getMapperFactory() {
        return mapperFactory;
    }
}
